/**
 * 
 */
package org.rollinitiative.d20web.charactersheet.client;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * @author bebopjmm
 *
 */
public class AttackView extends Composite
{

    private final TextBox nAttacksText_ = new TextBox();
    private final TextBox baseAttackText_ = new TextBox();
    private final TextBox meleeAttackText_ = new TextBox();
    private final TextBox rangedAttackText_ = new TextBox();
    private final TextBox grappleAttackText_ = new TextBox();

  private final FlexTable weaponsTable_ = new FlexTable();
    
    public AttackView()
    {
        VerticalPanel panel = new VerticalPanel();
//        panel.setBorderWidth(1);
        panel.add(new Label("Attack Stats"));
        
        Grid attackGrid = new Grid(3, 4);
        attackGrid.setWidget(0, 0, new Label("# Attacks:"));
        attackGrid.setWidget(0, 1, nAttacksText_);
        nAttacksText_.setReadOnly(true);
        nAttacksText_.setSize("4em", "2em");
        attackGrid.setWidget(1, 0, new Label("Base Attack:"));
        attackGrid.setWidget(1, 1, baseAttackText_);
        baseAttackText_.setReadOnly(true);
        baseAttackText_.setSize("4em", "2em");
        attackGrid.setWidget(0, 2, new Label("Melee Attack:"));
        attackGrid.setWidget(0, 3, meleeAttackText_);
        meleeAttackText_.setReadOnly(true);
        meleeAttackText_.setSize("4em", "2em");
        attackGrid.setWidget(1, 2, new Label("Ranged Attack:"));
        attackGrid.setWidget(1, 3, rangedAttackText_);
        rangedAttackText_.setReadOnly(true);
        rangedAttackText_.setSize("4em", "2em");
        attackGrid.setWidget(2, 2, new Label("Grapple Attack:"));
        attackGrid.setWidget(2, 3, grappleAttackText_);
        grappleAttackText_.setReadOnly(true);
        grappleAttackText_.setSize("4em", "2em");
        panel.add(attackGrid);
        panel.add(new Label ("Weapons"));
        panel.add(weaponsTable_);

        initWidget(panel);
        initView();
    }
    
    private void initView() {
        nAttacksText_.setText("0");
        baseAttackText_.setText("0");
        meleeAttackText_.setText("0");
        rangedAttackText_.setText("0");
        grappleAttackText_.setText("0");
        
        weaponsTable_.setWidget(0, 0, new Label("not yet implemented"));
    }

    public void setCharacter(CombatData combat)
    {
        nAttacksText_.setText(modifier(combat.getNumberAttacks()));
        meleeAttackText_.setText(modifier(combat.getMeleeAttack()[0]));
        rangedAttackText_.setText(modifier(combat.getRangedAttack()[0]));
        grappleAttackText_.setText(modifier(combat.getGrappleAttack()[0]));
    }
    
    public String modifier(int modifier) {
        if (modifier > -1) {
            return "+" + modifier;
        }
        else {
            return "" + modifier;
        }
    }
}
